package lq595;

import java.util.HashSet;
/*
 * lq595,AC
 */
public class Main {

	//邻接矩阵
	static int[][] m= {
            {0,1,0,0,0,1,0},
            {1,0,1,0,0,0,1},
            {0,1,0,1,0,0,1},
            {0,0,1,0,1,0,0},
            {0,0,0,1,0,1,1},
            {1,0,0,0,1,0,1},
            {0,1,1,0,1,1,0}
    };
	//led管编号
	static char[] led = {'a','b','c','d','e','f','g'};
	//hashset保存可行解
	static HashSet<String> ans = new HashSet<String>();
	public static void main(String[] args) {
		//全部节点为顶点，依次遍历
		for(int i=0;i<7;i++) {
			//初始化vis
			vis = new boolean[7];
			dfs(i);
		}

		//输出ans全部内容
		/*for(String t:ans)
			System.out.println(t);
		*/
		//输出ans里的结果
		System.out.println(ans.size());
	}

	//保存节点是否访问过
	static boolean[] vis;
	//dfs计算当前顶点开始的全部路径
	static void dfs(int v) {
		vis[v] = true;
		//输出当前路径，转成String存入hashset
		char[] t = {'0','0','0','0','0','0','0',};
		int c=0;
		for(int i=0;i<7;i++) {
			if(vis[i]) {
				t[c] = led[i];
				c++;
			}
		}
		String leds = String.valueOf(t);
		//加入HashSet
		ans.add(leds);
		//遍历v的全部连接点u
		for(int u=0;u<7;u++) {
			if(m[v][u]==1) {
				//如果没访问过
				if(vis[u]==false) {
					//邻接点为起点继续dfs
					dfs(u);	
					//注意要回溯
					vis[u] = false;
				}
			}		
		}
				
	}
}
